//
//  HEOrderServerTimeCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/10/28.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEOrderServerTimeCell.h"
#import "BRDatePickerView.h"

@interface HEOrderServerTimeCell ()<UITextFieldDelegate>

@property(nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) BRDatePickerView *datePickerView;
@property(nonatomic, strong) UITextField *textField;

@property(nonatomic, strong) UIImageView *arrowView;

@end


@implementation HEOrderServerTimeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self initUI];
     }
     return self;;
 }

- (void)initUI {
    
    _titleLb = [UILabel new];
    _titleLb.font = DYBlodFont(16);
    _titleLb.text = @"服务时间";
    _titleLb.textColor = CNavLightBlackColor;
    [self.contentView addSubview:_titleLb];
    
    _textField = [[UITextField alloc]init];
    _textField.placeholder = @"请选择服务时间";
    _textField.backgroundColor = [UIColor clearColor];
    _textField.font = DYFont(16);
    _textField.textAlignment = NSTextAlignmentLeft;
    _textField.delegate = self;
    _textField.userInteractionEnabled = NO;
    [self.contentView addSubview:_textField];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tfClick)];
    [self.contentView addGestureRecognizer:tap];
    
    _arrowView = [UIImageView new];
    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
    _arrowView.image = IMAGE_NAMED(@"go_gray");
    [self.contentView addSubview:_arrowView];
    
    [_arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.width.mas_offset(8);
        make.height.mas_offset(12);
    }];

     [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(self.contentView).mas_offset(20);
         make.left.equalTo(self.contentView).mas_offset(15);
      }];
    
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.contentView).mas_offset(20);
        make.left.equalTo(_titleLb.mas_right).mas_offset(10);
        make.right.equalTo(_arrowView.mas_left).mas_offset(-10);
       make.bottom.equalTo(self.contentView).mas_offset(-20);
    }];
}

- (void)tfClick {
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
    datePickerView.pickerMode = BRDatePickerModeYMDHM;
    datePickerView.title = @"服务时间";
//    datePickerView.selectDate = self.birthtimeSelectDate;
    datePickerView.isAutoSelect = YES;
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        self.textField.text = selectValue;
        self.formModel.order_serverTime = selectValue;
    };
    datePickerView.minDate = [NSDate stringToDate:[NSDate getNowDay:NSDateFormaterModeDay] formaterMode:NSDateFormaterModeDay];
    
    NSDate *date = [NSDate stringToDate:[NSDate getNowDay:NSDateFormaterModeDay] formaterMode:NSDateFormaterModeDay];
    NSString *str = [NSString stringWithFormat:@"%ld-%ld-%ld", date.year + 2, (long)date.month, (long)date.day];
    datePickerView.maxDate = [NSDate stringToDate:str formaterMode:NSDateFormaterModeDay];
    
    // 自定义弹框样式
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:CNavBgColor];
    datePickerView.pickerStyle = customStyle;
    [datePickerView show];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    _textField.text = formModel.order_serverTime;
}

#pragma mark - delegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return NO;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
